<!DOCTYPE html>
<head>
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
  <title>Coverage for {{gitiles_commit.project}} - {{path}}</title>
  <meta charset="utf-8">
  <style>
    .coverage-header {
      padding: 5px 10px;
      border-bottom: 1px solid #DBDBDB;
      background-color: #EEE;
      line-height: 24px;
      text-align: center;
      font-weight: bold;
      font-size: 18px;
    }
    table {
      border-collapse: collapse;
      border: 1px solid #EEE;
      font-family: -apple-system, sans-serif;
    }
    td {
      vertical-align: top;
      padding: 2px 8px;
      border-collapse: collapse;
      border-right: solid 1px #EEE;
      border-left: solid 1px #EEE;
      text-align: left;
    }
    tbody td {
      height: 18px;
    }
    td pre {
      margin-top: 0px !important;
      margin-bottom: 0px !important;
      display: inline-block;
      font-family: monospace;
      height: 15px;
    }
    td:first-child {
      border-left: none;
    }
    td:last-child {
      border-right: none;
    }
    thead a:hover {
      background-color: yellow;
    }
    .highlight-row:hover {
      background-color: #F0F0F0;
    }
    .sticky{
      position: sticky;
      top: 28px;
      padding: 8px;
      background: white;
      text-align: left;
    }
    .legend {
      font-family: monospace;
    }
    .legend .color-sample {
      padding: 2px 10px;
      border: 1px solid black;
      display: inline;
    }
    .covered-code {
      background-color: #E0F2F1;
    }
    .uncovered-code {
      background-color: #FFD1A4;
    }
    .partially-covered-code {
      background: linear-gradient(to right bottom, #E0F2F1 50%, #FFD1A4 50%);
    }
    .covered-count {
      color: BLUE;
      text-align: right;
    }
    .uncovered-count {
      color: DARKORANGE;
      text-align: right;
    }
    .partial-count {
      color: FUCHSIA;
      text-align: right;
    }
    .offset-anchor {
      display: block;
      position: relative;
      top: -90px;
      visibility: hidden;
    }
  </style>
  <script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="/ui/elements/cats-app.html">
  <link rel="import" href="/ui/elements/coverage/coverage-documentation.html">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="/ui/js/coverage.js"></script>
  <script>
    $(function() {
      document.getElementById('app').userInfo = {{ (user_info or {}) | tojson | safe }};
    });
    window.addEventListener('load', function(){
      // Insert a link to the first uncovered line if any.
      // TODO(crbug.com/958167): Make this view a polymer element, and implement
      // this behavior as part of it.
      var uncovered = document.getElementsByClassName("uncovered-count");
      if (uncovered.length > 0) {
        var link = document.createElement('a');
        link.href = document.querySelector('td.uncovered-code a').href;
        link.text = '(Jump to first uncovered line)';
        var placeholder = document.querySelector('#link-first-uncovered');
        placeholder.appendChild(link);
      }
    });
  </script>
</head>

{% macro HumanReadableCount(count) -%}
  {%- if count >= 1000000000000 -%}
    {{'{0:.1f}'.format(count/1000000000000.0)}}T
  {%- elif count >= 1000000000 -%}
    {{'{0:.1f}'.format(count/1000000000.0)}}G
  {%- elif count >= 1000000 -%}
    {{'{0:.1f}'.format(count/1000000.0)}}M
  {%- elif count >= 1000 -%}
    {{'{0:.1f}'.format(count/1000.0)}}K
  {%- else -%}
    {{count}}
  {%- endif %}
{%- endmacro %}

<body>
  <cats-app id="app" components="Infra>Test>CodeCoverage" page-header="Code Coverage: line-by-line coverage (Chrome Browser for {{platform_ui_name}})">
    <coverage-documentation></coverage-documentation>
    <br>
    <div style="font-size:18px">
    <form id="platform_select_form" method="get">
      Platform:
      <select id="platform_select" name="platform" onchange="switchPlatform()">
      {% for option in platform_select.options %}
        <option value="{{option.value}}" {% if option.selected %}selected="selected" {% endif %}>{{option.ui_name}}</option>
      {% endfor %}
      </select>
      {% for name, value in platform_select.params.iteritems() %}
        <input type="hidden" name="{{name}}" value="{{value}}"/>
      {% endfor %}
      Switch to <a href="/p/{{luci_project}}/coverage/component?host={{gitiles_commit.host}}&project={{gitiles_commit.project}}&ref={{gitiles_commit.ref}}&revision={{gitiles_commit.revision}}&path=>>&platform={{platform}}">Component View</a>.
      See <a href="/p/{{luci_project}}/coverage/dir?host={{gitiles_commit.host}}&project={{gitiles_commit.project}}&ref={{gitiles_commit.ref}}&platform={{platform}}&list_reports=true">Previous Reports</a>.
    </form>
    <br>
    <br>
    </div>
    <div style="width: fit-content;">
    <div class="coverage-header">
      <a href="/p/{{luci_project}}/coverage?host={{gitiles_commit.host}}&project={{gitiles_commit.project}}&platform={{platform}}">{{gitiles_commit.project}}</a>
      - {{gitiles_commit.revision[:7]}}
      - <a href="/p/{{luci_project}}/coverage?host={{gitiles_commit.host}}&project={{gitiles_commit.project}}&ref={{gitiles_commit.ref}}&revision={{gitiles_commit.revision}}&path={{path_root}}&platform={{platform}}">{{path_root}}</a>{% for name, sub_path in path_parts %}<a style="padding-left:.3ex;" title="{{sub_path}}" href="/p/{{luci_project}}/coverage/{{'dir' if name.endswith('/') else 'file'}}?host={{gitiles_commit.host}}&project={{gitiles_commit.project}}&ref={{gitiles_commit.ref}}&revision={{gitiles_commit.revision}}&path={{sub_path}}&platform={{platform}}">{{name}}</a>{% endfor %}
    </div>
    <table>
      <thead>
        <tr>
          <th class="sticky" colspan="3" style="top: -2px;">
            <div class="legend">
              Legend:
              <div class="color-sample covered-code"> Covered </div>
              <div class="color-sample uncovered-code"> Not Covered </div>
              <div class="color-sample incoverable-code"> Not-Compiled/Not-Instrumented </div>
            </div>
          </th>
        </tr>
        <tr>
          <th class="sticky">Line</th>
          <th class="sticky">Count</th>
          <th class="sticky">Source Code <span id="link-first-uncovered"></span></th>
        </tr>
      </thead>
      <tbody id="report-data-container">
      {% for num, info in data.line_to_data %}
        <tr id="{{num}}-row" class="highlight-row">
          {% if info.count == 0 %}
            <td class="uncovered-code" title="Uncovered line">
            <a href="#{{num}}"><pre>{{num}}</pre></a>
            <a id="{{num}}" class="offset-anchor"></a>
            </td>
            <td class="uncovered-count"><pre>0</pre></td>
            <td ><pre class="uncovered-code" title="Uncovered code">{{info.line}}</pre></td>
          {% elif info.is_partially_covered %}
            <td class="partially-covered-code" title="Partially covered line">
            <a href="#{{num}}"><pre>{{num}}</pre></a>
            <a id="{{num}}" class="offset-anchor"></a>
            </td>
            <td class="partial-count" title="{{info.count}}">
                <pre>{{HumanReadableCount(info.count)}}</pre>
            </td>
            <td>
              <pre>
                {%- for region in info.regions -%}
                  {%- if region.is_covered -%}
                    <span>{{region.text}}</span>
                  {%- else -%}
                    <span class="uncovered-code" title="Uncovered code">{{region.text}}</span>
                  {%- endif -%}
                {%- endfor -%}
              </pre>
            </td>
          {% elif info.count > 0 %}
            <td class="covered-code" title="Covered line">
            <a href="#{{num}}"><pre>{{num}}</pre></a>
            <a id="{{num}}" class="offset-anchor"></a>
            </td>
            <td class="covered-count" title="{{info.count}}">
              <pre>{{HumanReadableCount(info.count)}}</pre>
            </td>
            <td><pre>{{info.line}}</pre></td>
          {% else %}
            <td>
            <a href="#{{num}}"><pre>{{num}}</pre></a>
            <a id="{{num}}" class="offset-anchor"></a>
            </td>
            <td><!-- Intentionally empty. Count would go here. --></td>
            <td><pre>{{info.line}}</pre></td>
          {% endif %}
        </tr>
      {% endfor %}
      </tbody>
    </table>
    </div>
  </cats-app>
</body>
